<template>
  <div class="page-container">
    <div class="tabs">
      <div
        :class="['tab-button', activeTab === 'clay' ? 'active' : '']"
        @click="activeTab = 'clay'"
      >
        泥料
      </div>
      <div
        :class="['tab-button', activeTab === 'glaze' ? 'active' : '']"
        @click="activeTab = 'glaze'"
      >
        釉料
      </div>
    </div>

    <div class="form-section">
      <div class="form-item">
        <label class="form-label">任务编码</label>
        <div class="form-value">{{ taskInfo.code }}</div>
      </div>
      <div class="form-item">
        <label class="form-label">投料日期</label>
        <div class="form-value">{{ taskInfo.date }}</div>
      </div>
      <div class="form-item">
        <label class="form-label">备注</label>
        <uni-easyinput
          v-model="taskInfo.remarks"
          placeholder="输入内容"
          class="form-input"
        ></uni-easyinput>
      </div>
    </div>

    <div class="materials-list">
      <div v-for="(material, index) in materials" :key="index" class="material-item">
        <div class="material-index">{{ index + 1 }}</div>
        <div class="material-name">{{ material.name }}</div>
        <div class="material-input">
          <uni-easyinput
            v-model="material.weight"
            type="number"
            class="weight-input"
          ></uni-easyinput>
        </div>
        <div class="material-unit">公斤</div>
      </div>
    </div>

    <div class="footer">
      <button class="save-button" @click="save">保存</button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const activeTab = ref('clay')

const taskInfo = ref({
  code: 'NTL202504170001',
  date: '2025-04-17 09:15:35',
  remarks: ''
})

const materials = ref([
  { name: '麻泥', weight: 0 },
  { name: '石英泥', weight: 1000 },
  { name: '长丰泥', weight: 6100 },
  { name: '广东泥', weight: 7300 }
])

function save() {
  // 保存逻辑
  console.log('Saving data:', {
    taskInfo: taskInfo.value,
    materials: materials.value
  })
  uni.showToast({
    title: '保存成功',
    icon: 'success'
  })
}
</script>

<style scoped>
.page-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f5f5f5;
  box-sizing: border-box;
}

.tabs {
  display: flex;
  justify-content: flex-start;
  background-color: #fff;
  padding: 8px 15px;
  border-bottom: 1px solid #eee;
}

.search-input {
  flex: 1;
}

::v-deep .search-input .uni-easyinput__content {
  border: 1px dashed #ccc !important;
  border-radius: 4px;
}

.tab-button {
  padding: 6px 30px;
  border: 1px solid #ccc;
  background-color: #f0f0f0;
  color: #333;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.5;
  margin-right: 16rpx;
}
.tab-button:first-of-type {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}
.tab-button:last-of-type {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  border-left: none;
}
.tab-button.active {
  background-color: #2979ff;
  color: #fff;
  border-color: #2979ff;
}
.tab-button::after {
  border: none;
}

.form-section {
  background-color: #fff;
  padding: 15px;
  border-bottom: 1px dashed #ccc;
}

.form-item {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.form-label {
  width: 130rpx;
  color: #888;
  font-size: 14px;
}

.form-value {
  font-size: 14px;
  color: #333;
}

.form-input {
  flex: 1;
}
::v-deep .form-input .uni-input-input {
  font-size: 14px;
}
::v-deep .weight-input .uni-input-input {
  text-align: right;
}

.materials-list {
  background-color: #fff;
  padding: 10px 15px;
}

.material-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
}

.material-index {
  background-color: #f0f0f0;
  padding: 2px 8px;
  border-radius: 4px;
  margin-right: 10px;
  font-size: 12px;
}

.material-name {
  width: 80px;
  font-size: 16px;
}

.material-input {
  flex: 1;
  margin: 0 10px;
}

.material-unit {
  font-size: 16px;
  color: #333;
}

.footer {
  padding: 15px;
  background: #f5f5f5;
}

.save-button {
  width: 100%;
  padding: 12px;
  background-color: #2979ff;
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1.5;
}
.save-button:after {
  border: none;
}
</style>
